package com.crm.controller;

import com.crm.annotation.LogOperation;
import com.crm.dto.ContractDto;
import com.crm.entity.Contract;
import com.crm.result.ActivityResult;
import com.crm.result.PageResult;
import com.crm.result.Result;
import com.crm.service.ContractService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/contract")
@RestController
@Slf4j
public class ContractController {
    @Autowired
    private ContractService contractService;
    //条件分页查询
    @LogOperation(title = "合同管理")
    @GetMapping("/list")
    public ActivityResult<PageResult> contractPage(ContractDto contractDto){
        PageResult res = contractService.pageContract(contractDto);
        return ActivityResult.success("查询成功", null, res.getRows(), res.getTotal());
    }

    //新增合同
    @PostMapping
    public Result addContract(@RequestBody ContractDto contractDto){
        contractService.add(contractDto);
        return Result.success();
    }

    //跟进合同Id查询合同信息
    @GetMapping("/{id}")
    public Result<Contract> selectByContractId(@PathVariable Long id){
        Contract contract = contractService.selectContractById(id);
        return Result.success(contract);
    }

//    @GetMapping("/detail/{id}")
//    public Result<Contract> selectDetailByContractId(@PathVariable Long id){
//        Contract contract = contractService.selectContractById(id);
//        return Result.success(contract);
//    }
    @PutMapping("/changeContract/{id}")
    public Result changeContract(@PathVariable Long id){
        contractService.changeContract(id);
        return Result.success();
    }

}
